﻿using System;
using System.Drawing.Printing;
using System.Windows.Forms;

namespace Administracja
{
    public partial class Zestawienia : Form
    {
        private PrintDocument _printDok;

        public Zestawienia()
        {
            InitializeComponent();
            dataOd.Value = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
            dataDo.Value = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.DaysInMonth(DateTime.Today.Year, DateTime.Today.Month));
        }

        private void UstawTyp()
        {
            _printDok = new PrintDocument();
            var druk = new Druk(dataOd.Value, dataDo.Value);

            if (faktury_rad.Checked)
            {
                _printDok.PrintPage += druk.FakturyZestawieniePrintPage;
            }
            else
            {
                if (wplaty_rad.Checked)
                {
                    _printDok.PrintPage += druk.WplatyZestawieniePrintPage;
                }
                else
                {
                    if (wydatki_rad.Checked)
                    {
                        _printDok.PrintPage += druk.WydatkiZestawieniePrintPage;
                    }
                    else
                    {
                        _printDok.PrintPage += druk.OdsetkiZestawieniePrintPage;
                    }
                }
            }
        }

        private void ZamknijClick(object sender, EventArgs e)
        {
            Close();
        }

        private void DrukujClick(object sender, EventArgs e)
        {
            UstawTyp();

            print_dia.Document = _printDok;
            if (print_dia.ShowDialog() != DialogResult.OK) return;
            try
            {
                _printDok.Print();
            }
            catch (Exception ex)
            {
                Wyjatki.Error(ex);
            }
        }

        private void PodgladClick(object sender, EventArgs e)
        {
            UstawTyp();

            podglad_dia.Document = _printDok;
            ((Form)podglad_dia).WindowState = FormWindowState.Maximized;
            podglad_dia.PrintPreviewControl.Zoom = 1.5;
            podglad_dia.ShowDialog();
        }
    }
}
